#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mem(x) memset(x,0,sizeof(x))
#define endl "\n"
#define printYes cout << "Yes\n"
#define printYES cout << "YES\n"
#define printNo cout << "No\n"
#define printNO cout << "NO\n"
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define mkp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,j,k) for (int i=(j);i<=(k);i++)
#define per(i,j,k) for (int i=(j);i>=(k);i--)
#define pcnt(x) __builtin_popcount(x)
mt19937 rnd(time(0));
template<class T>void chkmin(T&x,T y){x=min(x,y);}
template<class T>void chkmax(T&x,T y){x=max(x,y);}

const ll inf=1000000000000000000; 
//const ll inf=1000000000;
//const ll mod=998244353;
//const ll mod=1000000007;

const int N=1000005;
int n,m; 
char a[N];
int s[N];
int f[21][N];
void init()
{
	int t=__lg(n+1);
	rep(i,0,n) f[0][i]=s[i];
	rep(k,1,t) rep(i,0,n-(1<<k)+1)
	{
		f[k][i]=max(f[k-1][i],f[k-1][i+(1<<(k-1))]);
	}
}
inline int query(int l,int r)
{
	int t=__lg(r-l+1);
	return max(f[t][l],f[t][r-(1<<t)+1]);
}
inline int calc(int l,int r)
{
	int res=query(l,r)-s[l-1];
	if (s[r]<s[l-1]) chkmax(res,1);
	else chkmax(res,0);
	return res;
}
int buc[N*2];
int nxt[21][N],val[21][N];
int ask(int l,int r)
{
	int v=0,res=0,d=0;
	l--;
	per(k,20,0)
	{
		if (nxt[k][l]<=r)
		{
			res+=(1<<k);
			chkmax(v,val[k][l]);
			l=nxt[k][l];
		}
	}
	if (l!=r)
	{
		chkmax(v,calc(l+1,r));
		d=s[r]-s[l];
	}
	else d=0;
	res+=v-d;
	return res;
}

int main()
{
	freopen("good.in","r",stdin);
	freopen("good.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin >> n >> m;
	rep(i,1,n) cin >> a[i];
	rep(i,1,n)
	{
		if (a[i]=='0') s[i]=s[i-1]-1;
		else s[i]=s[i-1]+1;
	}
	init();
	per(i,n,0)
	{
		if (buc[s[i]-1+N]) 
		{
			nxt[0][i]=buc[s[i]-1+N];
			val[0][i]=calc(i+1,buc[s[i]-1+N]);
		}
		else nxt[0][i]=n+1;
		buc[s[i]+N]=i;
	}
	rep(k,0,20) nxt[k][n+1]=n+1;
	rep(k,1,20) rep(i,0,n) 
	{
		nxt[k][i]=nxt[k-1][nxt[k-1][i]];
		val[k][i]=max(val[k-1][i],val[k-1][nxt[k-1][i]]);
	}
	int ans=0;
	rep(i,1,m)
	{
		int l,r;
		cin >> l >> r;
		ans^=ask(l,r);
	}
	cout << ans;
	return 0;
}
